<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
class DbView extends Controller {

	function setVars(){
		$this->tpl['head'] = '';
        $this->tpl['title'] = 'Database Page';
        $this->tpl['sidebar'] = $this->tm->randomBlock();
        $this->slug = $this->uri->segment(3, FALSE) ;
		$this->uid = $this->session->userdata('uid');
	}
	function __construct()
	{
		parent::Controller();
        $this->load->model('Tamer_Model', 'tm');
        $this->setVars();
        $this->load->scaffolding('view');
	}

	function pages()
	{
        $this->getdb();
        if($this->dbdata->Groups > 1){
            $this->auth->CheckTaMeR($this->dbdata->Groups);
        }
        $this->tpl['title'] = $this->dbdata->Title;
        $this->tpl['body']  = $this->phpWrapper($this->dbdata->Body);
        $this->load->view('blank', $this->tpl);
    }
    
    function getdb()
    {
        if($this->slug == FALSE){
            show_error('No direct script access allowed');
        }else{
            $query = $this->db->getwhere('view', array('slug' => $this->slug), 1);
            if($query->num_rows() == 0) {
                show_404('Page name');
            }else{
                $dbdata = $query->row_array();
                $this->vid = $dbdata['id'];
                $this->dbdata = (object) $dbdata;
            }
        }
    }

    function phpWrapper($content) {
        ob_start();
        $content = str_replace('<'.'?php','<'.'?',$content);
        eval('?'.'>'.trim($content).'<'.'?');
        $content = ob_get_contents();
        ob_end_clean();
        return $content;
    }
}
?>
